package trees;

public class JudgeSameTree {
    public boolean isSameTree(TreeNode tree1, TreeNode tree2) {
        if (tree1 == null && tree2 == null) {
            return true;
        }

        if (tree1 == null || tree2 == null) {
            return false;
        }

        if (tree1.val != tree2.val) {
            return false;
        }

        return isSameTree(tree1.left, tree2.left) && isSameTree(tree1.right, tree2.right);
    }

    public static void main(String[] args) {
        TreeNode tree1 = TreeNode.buildTree(1);
        TreeNode tree2 = TreeNode.buildTree(2);

        JudgeSameTree sameTree = new JudgeSameTree();
        boolean isSame = sameTree.isSameTree(tree1, tree2);
        System.out.println("is same tree? " + isSame);
    }
}
